/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package PropertyRental.war.servlets;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Bast
 */
class LoginAction extends Action {

    public LoginAction(String success, String fail){
        super(success, fail);
    }

    @Override
    public String perform(HttpServletRequest req) {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        boolean loggedIn = loginEJB.login(username, password);
        if (loggedIn){
            HttpSession session = req.getSession();

            synchronized(session) {
                session.setAttribute("account",loginEJB.getAccount()); 
            }
            return this.getSuccesspage();
        }
        else
            return this.getFailpage();
    }

}
